home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Dialectic 1.2 / source / Dialectic ƒ / Raw dialects ƒ / pig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  2.1 KB  |  79 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        pig.c
  4.  
  5. Purpose:    This module handles actually converting text into Pig Latin.
  6.  
  7.  
  8. Dialectic -=- dialect text conversion extraordinare
  9. Copyright ©1994, Mark Pilgrim
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "dialectic dispatch.h"
  29. #include "dialectic utilities.h"
  30. #include "program globals.h"
  31.  
  32. void ConvertPig(void)
  33. {
  34.     Str255            theConsonants;
  35.     Str255            thisWord;
  36.     int                i;
  37.     int                origLength;
  38.     Boolean            firstIsCaps;
  39.     Boolean            isAllCaps;
  40.     
  41.     if (!IsAlpha(ThisChar()))
  42.     {
  43.         StoreChar(ThisChar());
  44.         InputPlus(1);
  45.         return;
  46.     }
  47.     
  48.     origLength=GetRestOfWord(thisWord);
  49.     if (thisWord[0]==0x00)    return;
  50.     
  51.     firstIsCaps=IsUpperAlpha(thisWord[1]);
  52.     isAllCaps=IsAllCaps(thisWord);
  53.     
  54.     theConsonants[0]=0x00;
  55.     for (i=1; i<=origLength; i++)
  56.     {
  57.         if (IsConsonant(thisWord[i]))
  58.             theConsonants[++theConsonants[0]]=thisWord[i];
  59.         else
  60.             i=origLength+1;
  61.     }
  62.     
  63.     if (theConsonants[0]>0x00)
  64.     {
  65.         for (i=1; i<=origLength-theConsonants[0]; i++)
  66.             thisWord[i]=thisWord[i+theConsonants[0]];
  67.         for (i=1; i<=theConsonants[0]; i++)
  68.             thisWord[origLength-theConsonants[0]+i]=isAllCaps ? theConsonants[i]&0xdf :
  69.                 theConsonants[i]|0x20;
  70.         if (firstIsCaps)
  71.             thisWord[1]&=0xdf;
  72.     }
  73.  
  74.     thisWord[++thisWord[0]]=isAllCaps ? 'A' : 'a';
  75.     thisWord[++thisWord[0]]=isAllCaps ? 'Y' : 'y';
  76.     StoreString(thisWord);
  77.     InputPlus(origLength);
  78. }
  79.